package com.ruoyi.controller;

import com.ruoyi.service.IBookService;
import com.ruoyi.service.IStatisticsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.OffsetDateTime;
import java.util.Map;

/**
 * 统计可视化controller
 */
@RestController()
@RequestMapping("/statistics")
public class StatisticsController extends BaseController {

    @Resource
    private IStatisticsService statisticsService;
    @Resource
    private IBookService bookService;

    /**
     * 折线图：展示每一个月借出图书的数量
     * @return
     */
    @GetMapping("/lendStatistics")
    public TableDataInfo lendStatistics(String year){
        return getDataTable(statisticsService.lend(year));
    }

    /**
     * 柱状图，展示作者对应的图书的数量
     */
    @GetMapping("/authorBookNum")
    public Map<String,Integer> authorBookNumStatistics(){
        return  bookService.getAuthorBookNum();
    }


    /**
     * 饼状图：展示每一种语言对应的图书的数量
     * @return
     */
    @GetMapping("/languageNum")
    public Map<String,Integer> languageNum(){
        return bookService.getLanguageNum();
    }

    /**
     * 每一天图书变化数量
     * @return
     */
    @GetMapping("/bookNum")
    public Map<String,Integer> getEveryDayBookNum(){
        return bookService.getEveryDayBookNum();
    }


    /**
     * 每一天借出图书数量变化
     * @param year
     * @param month
     * @return
     */
    @GetMapping("/lendList")
    public Map<String,Integer> everydayLendList(int year,int month){
        return statisticsService.getLendList(year,month);
    }

    /**
     * 每个月的丢失图书数量
     * @return
     */
    @GetMapping("/lostCount")
    public TableDataInfo everyMonthLostList(String year){
        return getDataTable(statisticsService.getLostCount(year));
    }

    /**
     * 最受欢迎作者榜
     */
     @GetMapping("/popularAuthor")
    public Map<String,Integer> authorLendBookCount(){
         return statisticsService.getMostPopularAuthor();
     }

    /**
     * 归还逾期率
     */
    @GetMapping("/backLater")
    public Map<Integer,Integer> backLaterCount(){
        return statisticsService.backLaterStatistics();
    }
}
